package cn.com.vastbase.hibernate.sample.springmvc.basic.impl;

import cn.com.vastbase.hibernate.sample.springmvc.basic.IBaseDAO;
import org.hibernate.Session;
import org.springframework.orm.hibernate5.HibernateTemplate;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Transactional
public class BaseDAOImpl implements IBaseDAO {

    private static HibernateTemplate hibernateTemplate;

    public void setHibernateTemplate(HibernateTemplate hibernateTemplate) {
        this.hibernateTemplate = hibernateTemplate;
    }

    public Session getSession() {
        return hibernateTemplate.getSessionFactory().getCurrentSession();
    }

    public void save(Object obj) {
        hibernateTemplate.saveOrUpdate(obj);
    }

    public List<?> find(String hql) {
        return hibernateTemplate.find(hql);
    }

}
